<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="员工姓名" prop="userId">
            <el-select disabled class="w100" @change="jxcrtxr" v-model="dataForm.userId" placeholder="请选择用户" clearable filterable>
              <el-option v-for="item in xczxtrt" :key="item.id" :label="item.realName" :value="item.id"> </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入职企业">
            {{ dataForm.companyName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入职天数"> {{ dataForm.companyDay || "0" }}天 </el-form-item>
        </el-col>
        <el-col :span="12" v-if="dataForm.userId">
          <el-form-item label="身份证">
            {{ dataForm.idCard }}
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="dataForm.userId">
          <el-form-item label="发薪卡名">
            {{ dataForm.payCardName }}
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="dataForm.userId">
          <el-form-item label="卡号">
            {{ dataForm.payCard }}
          </el-form-item>
        </el-col>

        <el-col :span="12" v-if="dataForm.userId">
          <el-form-item label="所属支行">
            {{ dataForm.payCardBranch }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请时间">
            {{ dataForm.createTime }}
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label=" 交易金额" prop="balance">
            <el-input v-model="dataForm.balance" placeholder="申请金额"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label=" 工作天数" prop="jobDay">
            <el-input v-model="dataForm.jobDay" placeholder="工作天数"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="审核" prop="isPass" v-if="dataForm.id">
            <el-radio-group v-model="dataForm.isPass">
              <el-radio label="2">通过</el-radio>
              <el-radio label="3">拒绝</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="打卡记录">
            <span class="ls sz" @click="xcxcdsf">点击查看</span>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- <el-form-item label="公司id" prop="companyId">
        <el-input v-model="dataForm.companyId" placeholder="公司id"></el-input>
      </el-form-item>
      <el-form-item label="公司名称" prop="companyName">
        <el-input v-model="dataForm.companyName" placeholder="公司名称"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="转帐流水" prop="recordNo">
        <el-input v-model="dataForm.recordNo" placeholder="转帐流水"></el-input>
      </el-form-item> -->

      <!-- <el-form-item label="交易类型" prop="recordType">
        <el-radio-group v-model="dataForm.recordType">
              <el-radio label="1"  >工资</el-radio>
              <el-radio label="2"  >转账</el-radio>
              <el-radio label="3"  >借款</el-radio>
            </el-radio-group>
      </el-form-item> -->
      <!-- <el-form-item label="交易渠道" prop="recordChannel">
        <el-radio-group v-model="dataForm.recordChannel">
              <el-radio label="1"  >银行卡</el-radio>
              <el-radio label="2"  >微信</el-radio>
              <el-radio label="3"  >其他</el-radio>
            </el-radio-group>
      </el-form-item> -->

      <!-- <el-form-item label="转账截图" v-if="dataForm.isPass==2">
       <div class="xzcsretrt">
        <dimg :dximg="dataForm.recordImg" @getimg="xzczxtrt"></dimg>
       </div>
      </el-form-item> -->
      <el-form-item label="拒绝原因" v-if="dataForm.isPass == 3">
        <el-input rows="10" v-model="dataForm.content" type="textarea" placeholder="请输入拒绝原因"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>

  <el-dialog v-model="visibleer" title="打卡记录" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="companyName" label="公司名称" />
      <el-table-column prop="clockAddr" label="打卡地点" />
      <el-table-column prop="clockTime" label="打卡时间" width="160" />
    </el-table>
    <template #footer>
      <el-button @click="visibleer = false">取消</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus";
import { dxget } from "@/utils/utils";
const emit = defineEmits(["refreshDataList"]);
import dimg from "@/components/dimg.vue";
const xczxtrt = ref([]);
const visible = ref(false);
const dataFormRef = ref();
const visibleer = ref(false);
const tableData = ref([]);
const dataForm = reactive({
  id: "",
  userId: "",
  realName: "",
  idCard: "",
  payCard: "",
  bankName: "",
  balance: "",
  companyId: "",
  companyName: "",
  recordNo: "",
  type: "",
  recordType: "",
  recordChannel: "",
  recordTime: "",
  recordImg: "",
  isPass: "",
  createTime: "",
  updateTime: ""
});
const xcxcdsf = async () => {
  visibleer.value = true;
  const { list }: any = await dxget("/api/userclock/page", { userId: dataForm.userId });
  console.log(list);
  tableData.value = list;
};

const rules = ref({
  userId: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  realName: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  idCard: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  payCard: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  bankName: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  balance: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  companyId: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  companyName: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  recordNo: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  type: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  recordType: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  recordChannel: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  recordTime: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  recordImg: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  isPass: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  createTime: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  updateTime: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  jobDay: [{ required: true, message: "必填项不能为空", trigger: "blur" }]
});

const init = (id?: number) => {
  visible.value = true;
  dataForm.id = "";
  dataForm.recordImg = "";
  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (id) {
    getInfo(id);
  }
};

// 获取信息
const getInfo = (id: number) => {
  baseService.get("/api/userbalancelog/" + id).then((res) => {
    Object.assign(dataForm, res.data);
  });
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    dataForm.type = 1;
    if (!valid) {
      return false;
    }

    (!dataForm.id ? baseService.post : baseService.put)("/api/userbalancelog", dataForm).then((res) => {
      ElMessage.success({
        message: "成功",
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};
const jmkxcf = async () => {
  const { list } = await dxget("/api/user/page", {
    limit: 999,
    isAuthentication: true
  });
  xczxtrt.value = list;
};
jmkxcf();
defineExpose({
  init
});
const xzczxtrt = (data) => {
  dataForm.recordImg = data;
};
const jxcrtxr = (data) => {
  const obj = xczxtrt.value.filter((a) => a.id == data)[0];
  dataForm.realName = obj.payName;
  dataForm.idCard = obj.idCard;
  dataForm.payCard = obj.payCard;
  dataForm.bankName = obj.payCardName;
  dataForm.payCardBranch = obj.payCardBranch;
};
</script>
